package com.zhoug.router;

import android.content.Context;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.service.DegradeService;
import com.zhoug.logging.Logger;

/**
 * 服务接口拦截跳转失败
 * @Author HK-LJJ
 * @Date 2019/10/28
 * @Description TODO
 */
//要用ARouter跳转才能拦截到，用Intent隐式或显示跳转无法拦截，出错还是会crash
@Route(path = "/arouterbase/degrade")
public class DegradeServiceImp implements DegradeService {
    private static final String TAG = ">>>DegradeServiceImp";
    @Override
    public void onLost(Context context, Postcard postcard) {
        String errorMsg="路径不正确:"+postcard.getPath();
        Logger.e(TAG, "onLost:"+errorMsg);
//        LogUtils.e(TAG, "context:"+context);
        //context是navigation传入的Context对象,没有传入则为null
        if(context!=null){
            Toast.makeText(context, errorMsg, Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void init(Context context) {
        Logger.e(TAG, "服务接口拦截跳转失败 init:");
    }
}
